package com.xywl.escort.view.message

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.trello.rxlifecycle2.LifecycleTransformer
import com.xywl.escort.R
import com.xywl.escort.base.BaseActivity
import com.xywl.escort.bean.BaseResp
import com.xywl.escort.bean.MessageResp
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_notice_detail.*
import timber.log.Timber
import javax.inject.Inject

@Route(path = "/xy/message/detail")
class MessageDetailActivity : BaseActivity(), MessageDetailContract.View {

    @Autowired
    @JvmField
    var bean: MessageResp.DataBean.ListBean? = null

    @Inject
    lateinit var mPresenter: MessageDetailContract.Presenter

    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_notice_detail)
        ARouter.getInstance().inject(this)

        showBackButton()
        setTitleText(getString(R.string.message))

        Timber.tag("MessageDetailActivity").e("bean=$bean")

        val title = bean!!.title
        val time = bean!!.createTime
        val content = bean!!.content
        text_title.text = title
        text_time.text = time
        text_content.text = content

        val id = bean!!.id
        mPresenter.takeView(this)
        mPresenter.updateMessageStatus(id, 1)
    }

    override fun isActive(): Boolean {
        return false
    }

    override fun <T : Any?> bindToLife(): LifecycleTransformer<T> {
        return this.bindToLifecycle()
    }

    override fun updateMessageStatusSuccess(resp: BaseResp?) {
        Timber.tag("updateMessageStatusSuccess").e("resp=$resp")
    }

    override fun updateMessageStatusFailure() {
        Timber.tag("updateMessageStatusFailure").e("failure")
    }
}
